package com.edaoe.module.log;

import com.edaoe.util.DateUtil;
import com.edaoe.util.FileUtil;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;

import java.io.File;
import java.util.Date;

/**
 * Created by Dull on 2017/4/27 0027.
 */
public class LogService {

    public String index(String dateStr){
        String logFilePath = PropKit.use("log4j.properties").get("log4j.appender.file.File");
        if (StrKit.notBlank(dateStr)) {
            String suffix;
            Date date = new Date();
            if (dateStr.length() == 2)
                suffix = DateUtil.format(date, "yyyyMM") + dateStr;
            else if (dateStr.length() == 4)
                suffix = DateUtil.format(date, "yyyy") + dateStr;
            else
                suffix = dateStr;
            logFilePath += "." + suffix;
        }
        File logFile=new File(logFilePath);
        if (!logFile.exists())
            return "没有错误记录";
        return FileUtil.read(logFile);
    }
}
